 <template>
   <el-card shadow="always" class="box-card">
      <div class="card-name search-item">
        <div class="name width2">代理商等级</div>
        <div class="mr-15">
          <el-button size="medium" type="primary" @click="add">新 增</el-button>
        </div>
      </div>
      <div class="content-con">
        <div class="bank-form">
          <div class="form-item">
            <el-table
              :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)"
              class="table"
              stripe border
              :header-cell-style="{background:'#f3f3f3',textAlign: 'center'}"
              :cell-style="{ textAlign: 'center' }">
              <el-table-column type="index" width="50">
              </el-table-column>
              <el-table-column prop="agent_level" label="代理商级别">
              </el-table-column>
              <el-table-column prop="agent_area" label="代理范围">
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <el-button type="text" @click="handleEdit(scope.row)">
                    <i class="el-icon-edit"></i>编辑
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <!-- 分页-页码 -->
          <div class="page">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              :page-sizes="[5, 10, 15, 20]"
              :page-size="pagesize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="tableData.length">
            </el-pagination>
          </div>
        </div>
      </div>
      <agent-level ref="AgentLevel" :rows="rows"></agent-level>
   </el-card>

 </template>
<script>
import AgentLevel from '@/components/agent-manage/AgentLevel';
export default {
  components: {
    AgentLevel
  },
  data () {
    return {
      rows: '',
      currentPage: 1, //当前页码
      pagesize: 5,    //每页的数据条数
      tableData: [
        {
          agent_level: '总代理',
          agent_area: ''
        },
        {
          agent_level: '一级代理',
          agent_area: ''
        },
        {
          agent_level: '二级代理',
          agent_area: ''
        }
      ]
    }
  },

  methods: {
    //新增
    add(){
      this.$nextTick(()=>{
        this.$refs.AgentLevel.openAdd()
      });
    },

    //编辑操作
    handleEdit(row){
      this.rows = row;
      this.$nextTick(()=>{
        this.$refs.AgentLevel.openEdit()
      });
    },

    //每页条数改变时触发事件,选择一页显示多少行
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.currentPage = 1;
      this.pagesize = val;
    },
    // 当前页改变时触发 跳转其他页
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage = val;
    }
  }
}
</script>
<style lang="scss">

</style>
